var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = t(require("../../../utils/util")), i = getApp();

Page({
    data: {
        keywords: "",
        store_id: 0,
        activeName: 0,
        titleArr: [ "全部活动", "未开始", "活动中", "已结束" ],
        dataList: [],
        showEndP: !1,
        cloneIndex: 0,
        has_many_level: {},
        activeItem: {},
        activeID: 0,
        posterShow: !1,
        showShare: !1,
        options: [ {
            name: "分享好友",
            icon: "wechat",
            openType: "share"
        }, {
            name: "分享海报",
            icon: "poster"
        } ],
        isLoadMore: !0
    },
    onLoad: function(t) {
        t.store_id && this.setData({
            store_id: t.store_id
        }), this.setNewArr();
    },
    setNewArr: function() {
        var t = this;
        this.data.titleArr.forEach(function(a, e) {
            t.data.dataList.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), console.log("dataList:::", this.data.dataList), this.handleClick();
    },
    clickShare: function(t) {
        this.setData({
            activeItem: t.target.dataset.item,
            activeID: t.target.dataset.item.id,
            showShare: !0
        });
    },
    onClose: function() {
        this.setData({
            showShare: !1
        });
    },
    onSelect: function(t) {
        "分享海报" == t.detail.name && this.setData({
            posterShow: !0
        });
    },
    tabClick: function(t) {
        this.setData({
            activeName: t.detail.index
        }), this.handleClick();
    },
    handleClick: function() {
        var t = this;
        if (!(this.data.dataList[this.data.activeName].list.length > 0)) {
            var s = i.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.index");
            i._getNetWork({
                url: s,
                data: {
                    status: this.data.activeName,
                    store_id: this.data.store_id,
                    page: this.data.page,
                    title: this.data.keywords
                },
                success: function(i) {
                    var s = i.data;
                    if (1 == s.result) {
                        var o;
                        t.setData((a(o = {}, "dataList[" + t.data.activeName + "].isLoadMore", !0), a(o, "dataList[" + t.data.activeName + "].total_page", s.data.last_page), 
                        a(o, "dataList[" + t.data.activeName + "].list", s.data.data), o));
                        for (var d = 0; d < t.data.dataList[t.data.activeName].list.length; d++) {
                            var n, r = e.default.formatTime(new Date(1e3 * t.data.dataList[t.data.activeName].list[d].start_time)), c = e.default.formatTime(new Date(1e3 * t.data.dataList[t.data.activeName].list[d].end_time));
                            t.setData((a(n = {}, "dataList[" + t.data.activeName + "].list[" + d + "].start_time", r), 
                            a(n, "dataList[" + t.data.activeName + "].list[" + d + "].end_time", c), n));
                        }
                    } else wx.showToast({
                        title: s.msg,
                        icon: "none",
                        duration: 1e3
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onSearch: function() {
        this.setData(a({}, "dataList[" + this.data.activeName + "].list", [])), this.handleClick();
    },
    onChange: function(t) {
        this.setData({
            keywords: t.detail
        });
    },
    closeEndP: function() {
        this.setData({
            showEndP: !1
        });
    },
    endGrouplist: function(t) {
        this.setData({
            cloneIndex: t.currentTarget.dataset.index,
            has_many_level: t.currentTarget.dataset.item.has_many_level,
            showEndP: !0
        });
    },
    toDataStatistics: function(t) {
        var a = t.currentTarget.dataset.id;
        a && wx.navigateTo({
            url: "/packageC/o2o/groupDataStatistics/groupDataStatistics?id=" + a
        });
    },
    toOpenGroupList: function(t) {
        var a = t.currentTarget.dataset.id;
        a && wx.navigateTo({
            url: "/packageC/o2o/openGroupList/openGroupList?id=" + a + "&store_id=" + this.data.store_id
        });
    },
    createActivity: function() {
        wx.navigateTo({
            url: "/packageC/o2o/createGroup/createGroup?store_id=" + this.data.store_id
        });
    },
    editActivity: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/o2o/createGroup/createGroup?store_id=" + this.data.store_id + "&id=" + a
        });
    },
    closelevel: function(t) {
        var a = t.currentTarget.dataset, e = a.num, i = a.id, s = a.index, o = this;
        wx.showModal({
            title: "提示",
            content: "是否手动结束".concat(e, "人团"),
            success: function(t) {
                t.confirm ? o.closelevelFun(e, i, s) : t.cancel && console.log("用户点击取消");
            }
        });
    },
    closelevelFun: function(t, e, s) {
        var o = this, d = i.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.close-level");
        i._getNetWork({
            url: d,
            data: {
                id: e
            },
            success: function(t) {
                var e, i = t.data;
                (wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1e3
                }), 1 == i.result) && o.setData((a(e = {}, "dataList[" + o.data.activeName + "].list[" + o.data.cloneIndex + "].has_many_level[" + s + "].status", 2), 
                a(e, "has_many_level[" + s + "].status", 2), e));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.dataList[this.data.activeName].isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    _getMoreData: function() {
        var t = this;
        if (this.setData(a({}, "dataList[" + t.data.activeName + "].isLoadMore", !1)), !(this.data.dataList[this.data.activeName].page >= this.data.dataList[this.data.activeName].total_page)) {
            this.data.dataList[this.data.activeName].page = this.data.dataList[this.data.activeName].page + 1;
            var e = i.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.index");
            e += "&page=" + this.data.dataList[this.data.activeName].page, i._getNetWork({
                url: e,
                data: {
                    status: t.data.activeName,
                    store_id: t.data.store_id,
                    page: t.data.page,
                    title: t.data.keywords
                },
                success: function(e) {
                    var i = e.data;
                    if (1 == i.result) {
                        var s, o = i.data;
                        t.setData((a(s = {}, "dataList[" + t.data.activeName + "].isLoadMore", !0), a(s, "dataList[" + t.data.activeName + "].list", t.data.dataList[t.data.activeName].list.concat(o.data)), 
                        s));
                    } else {
                        var d;
                        t.setData((a(d = {}, "dataList[" + t.data.activeName + "].isLoadMore", !1), a(d, "dataList[" + t.data.activeName + "].page", t.data.dataList[t.data.activeName].page - 1), 
                        d));
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onShareAppMessage: function(t) {
        var a = wx.getStorageSync("yz_uid"), e = "";
        a && (e = a);
        var i = {
            title: "门店拼团",
            path: "/packageC/o2o/o2oGroupActivitylist/o2oGroupActivitylist?mid=" + e
        };
        return "{}" != JSON.stringify(this.data.activeItem) && "button" == t.from && (i.title = this.data.activeItem.title, 
        i.path = "/packageA/detail_v2/detail_v2?id=" + this.data.activeItem.id + "/" + this.data.store_id + "&name=group&mid=" + e, 
        i.imageUrl = this.data.activeItem.has_one_goods.thumb), this.data.goodshare_info = {}, 
        i;
    }
});